import request from '../utils/request'
import { api } from '../config/config'
import { md5 } from '../lib/md5'

/**
 * WAP发送手机验证码
 * @param mobile
 * @param captcha
 * @param uuid
 */
export function sendMobileLoginSms(mobile, captcha, uuid) {
  return request.ajax({
    url: `/passport/mobile-binder/sms-code/${mobile}`,
    method:'post',
    params: {
      captcha,
      uuid
    }
  })
}

/**
 * 小程序登陆不要验证码登陆
 * @param uuid
 * @param params
 */
export function loginBymini(uuid,params) {
  return request.ajax({
    url: `/passport/mobile-binder-mini/${uuid}?platformType=1&platformNo=TYSH0000000000`,
    method:'post',
    params
  })
}

/**
 * 第三方登录绑定【通过手机验证码方式登录】
 * @param uuid
 * @param params
 */
export function loginByMobileConnect(uuid, params) {
  return request.ajax({
    url: `/passport/mobile-binder/${uuid}?platformType=1&platformNo=TYSH0000000000`,
    method: 'post',
    params
  })
}

/**
 * 注册绑定
 * @param uuid
 * @param params
 */
export function registerBindConnect(uuid, params) {
  const _params = { ...params }
  _params.password = md5(_params.password)
  return request.ajax({
    url: `/passport/mini-program/register-bind/${uuid}?platformType=1&platformNo=TYSH0000000000`,
    method: 'post',
    params: _params
  })
}

/**
 * 获取当前登录的用户信息
 * @returns {AxiosPromise}
 */
export function getUserInfo() {
  return request.ajax({
    url: '/members',
    needToken: true,
    method: 'get'
  })
}

/**
 * 访问短链接
 * @param params
 */
export function accessShortLink(params) {
  return request.ajax({
    url: '/distribution/su/visit',
    method: 'get',
    params
  })
}

/**
 * 微信小程序自动登录
 */
export function loginByAuto(params) {
  return request.ajax({
    url: '/passport/mini-program/auto-login?platformType=1&platformNo=TYSH0000000000',
    method: 'get',
    loading: false,
    params
  })
}

/**
 * 加密数据解密验证
 * @param params
 */
export function accessUnionID(params) {
  return request.ajax({
    url: '/passport/mini-program/decrypt',
    method: 'get',
    loading: false,
    params
  })
}

/**
 * 登出
 * @param type
 * @returns {AxiosPromise}
 */
export function logout(type) {
  return request.ajax({
    url: type === 'WECHAT' ? '/account-binder/unbind/out' : '/members/logout',
    method:'post',
    needToken: true
  })
}